<template>
    <div>
        <el-dialog
                :title="title"
                :visible.sync="dialogVisible"
                width="50%"
                :show-close="true"
                :close-on-click-modal="false"
                v-dialogDrag
        >
            <el-form :model="model" :rules="rule" ref="registerRef" label-width="100px">
                <el-row>
                                                <el-col :span="12">
                                <el-form-item label="编码" prop="code">
                                        <el-input v-model.trim="model.code"
                                                  placeholder="请输入编码"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="编码名称" prop="codeName">
                                        <el-input v-model.trim="model.codeName"
                                                  placeholder="请输入编码名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="名称" prop="name">
                                        <el-input v-model.trim="model.name"
                                                  placeholder="请输入名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="状态码" prop="state">
                                        <el-input v-model.trim="model.state"
                                                  placeholder="请输入状态码"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="排序" prop="sort">
                                        <el-input v-model.trim="model.sort"
                                                  placeholder="请输入排序"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="备注" prop="remarks">
                                        <el-input v-model.trim="model.remarks"
                                                  placeholder="请输入备注"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="创建人ID" prop="creatorId">
                                        <el-input v-model.trim="model.creatorId"
                                                  placeholder="请输入创建人ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="修改人ID" prop="updateId">
                                        <el-input v-model.trim="model.updateId"
                                                  placeholder="请输入修改人ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="创建时间" prop="createTime">
                                        <el-date-picker
                                                v-model.trim="model.createTime"
                                                type="date"
                                                placeholder="选择创建时间日期">
                                        </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="修改时间" prop="updateTime">
                                        <el-date-picker
                                                v-model.trim="model.updateTime"
                                                type="date"
                                                placeholder="选择修改时间日期">
                                        </el-date-picker>
                                </el-form-item>
                            </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible=false">取 消</el-button>
                <el-button type="primary" @click="submitForm('registerRef')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {baseurl} from "@/api/api"
    import {httpAction} from "@/api/manage"

    export default {
        name: "dictSave",
        data() {
            return {
                model: {},
                disableSubmit: false,
                dialogVisible: false,
                url: {
                    add: this.$api.baseurl + '/dict/insert',
                    edit: this.$api.baseurl + '/dict/update'
                },
                title: '',
                rule: {
            id:
            {
                required:true, message
            :
                "请填写id", trigger
            :
                'blur'
            }
            ,            code:
            {
                required:true, message
            :
                "请填写编码", trigger
            :
                'blur'
            }
            ,            codeName:
            {
                required:true, message
            :
                "请填写编码名称", trigger
            :
                'blur'
            }
            ,            name:
            {
                required:true, message
            :
                "请填写名称", trigger
            :
                'blur'
            }
            ,            state:
            {
                required:true, message
            :
                "请填写状态码", trigger
            :
                'blur'
            }
            ,            sort:
            {
                required:true, message
            :
                "请填写排序", trigger
            :
                'blur'
            }
            ,            remarks:
            {
                required:true, message
            :
                "请填写备注", trigger
            :
                'blur'
            }
            ,            creatorId:
            {
                required:true, message
            :
                "请填写创建人ID", trigger
            :
                'blur'
            }
            ,            updateId:
            {
                required:true, message
            :
                "请填写修改人ID", trigger
            :
                'blur'
            }
            ,            createTime:
            {
                required:true, message
            :
                "请填写创建时间", trigger
            :
                'blur'
            }
            ,            updateTime:
            {
                required:true, message
            :
                "请填写修改时间", trigger
            :
                'blur'
            }
            
        },
        }
        },
        mounted() {

        },
        methods: {
            add() {
                this.edit({})
            },
            edit(record) {
                if (this.$refs['registerRef'] !== undefined) {
                    this.$refs['registerRef'].resetFields();
                }
                this.model = Object.assign({}, record);
                this.dialogVisible = true;
            },
            submitForm(formName) {
                const that = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let httpurl = '';
                        if (!this.model.id) {
                            httpurl += this.url.add;
                        } else {
                            httpurl += this.url.edit;
                        }
                        httpAction(httpurl, this.model).then((res) => {
                            if (res.data.code == 200) {
                                that.$message.success("操作成功");
                                that.$emit('ok');
                                this.dialogVisible = false
                            } else {
                                that.$message.warning("操作失败");
                            }
                        })
                    }

                })
            }
        }
    }
</script>

<style scoped>

</style>
